package com.wh.hotel.util;

import cn.hutool.core.date.DateUtil;
import com.google.common.collect.Lists;

import java.util.Date;
import java.util.List;

/**
 * @author wenhao
 */
public class DateWhUtil {

    public static Date addDays(Date cur, int days) {
        return DateUtil.offsetDay(cur, days);
    }

    /**
     *
     * @param cur
     * @param left 闭区间
     * @param right 开区间
     * @return
     */
    public static boolean isIn(Date cur, Date left, Date right) {
        if (left == null && right == null) {
            return true;
        }
        if (cur == null) {
            return false;
        }
        if (left == null) {
            return lt(cur, right);
        }
        if (right == null) {
            return ge(cur, left);
        }
        return lt(cur, right) && ge(cur, left);
    }

    public static boolean lt(Date s, Date t) {
        return s.getTime() < t.getTime();
    }

    public static boolean ge(Date s, Date t) {
        return s.getTime() >= t.getTime();
    }

    public static int getWeekNum(Date cur) {
        return DateUtil.dayOfWeekEnum(cur).getIso8601Value();
    }

    /**
     *
     * @param st 闭区间
     * @param en 闭区间
     * @return
     */
    public static List<Date> createDateByDay(Date st, Date en) {
        List<Date> result = Lists.newArrayList();
        Date cur = st;
        while (ge(en, cur)) {
            result.add(cur);
            cur = addDays(cur, 1);
        }
        return result;
    }
}
